<template>
    <div class="home">
        <div class="header">
            <div>用户管理</div>
        </div>
        <div class="center">
            <div class="center_top">
                <div>
                    <button @click="chanIsShowTableModal(true)">新建</button>
                    <input type="text" placeholder="按关键字搜索">
                </div>
                <div>
                    <button @click="revoca">撤销</button>
                </div>
            </div>
            <div class="table">
                <table width="900px" align="center" border="1px">
                    <tr >
                        <th v-for="item,index in titles" :key="index">{{item}}</th>
                    </tr>
                    <tr v-for="item,index in userArr" :key="item.id">
                        <td>
                            <input type="checkbox" :checked="item.isCheaked" @input="item.isCheaked=!item.isCheaked"/>
                        </td>
                        <td>{{item.name}}</td>
                        <td>{{item.age}}</td>
                        <td>{{item.sex}}</td>
                        <td>{{item.phone}}</td>
                        <td>{{item.location}}</td>
                        <td>
                            <button v-if="item.isDisabled"  @click="chanIsShowTableModal(true)">编辑</button>
                            <button v-else disabled="disabled">编辑</button>
                            <button v-if="item.isDisabled" @click="del(index)">删除</button>
                            <button v-else disabled="disabled" >删除</button>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="end">
            <button @click="delAll">批量删除</button>
        </div>
    </div>
</template>

<script>
import { mapMutations} from 'vuex'
export default {
    data () {
        return {
            titles:[" ","姓名","年龄","性别","联系电话","详细地址","操作"],
            userArr:[{
                id:0,
                isCheaked:false,
                name:"李四",
                age:16,
                sex:"nan",
                phone:"1365647852245",
                location:"广东省茂名市茂南区山阁镇莫午餐xxxx",
                isDisabled:true
            },
            {
                id:1,
                isCheaked:false,
                name:"李四",
                age:16,
                sex:"nan",
                phone:"1365647852245",
                location:"广东省茂名市茂南区山阁镇莫午餐xxxx",
                isDisabled:true
            },
            {
                id:2,
                isCheaked:false,
                name:"李四",
                age:16,
                sex:"nan",
                phone:"1365647852245",
                location:"广东省茂名市茂南区山阁镇莫午餐xxxx",
                isDisabled:true
            }]
        }
    },
    methods:{
        del(i){
            this.userArr.splice(i, 1)
        },
        delAll(){
            this.userArr = this.userArr.filter((item)=>{
                return item.isCheaked == false
            })
        },
        revoca(){
            this.userArr.filter((item)=>{
                if(item.isCheaked == true){
                    item.isDisabled = false
                }
            })
        },
        ...mapMutations({
            chanIsShowTableModal:'ShowTableModal/chanIsShowTableModal'
        })
    }
}
</script>

<style lang = "less">
    .home{
        .header{
            /* width: 1200px; */
            margin: 0 auto;
            height: 80px;
            line-height: 80px;
            background-color: #ccc;
            font-size:32px;
            font-weight: 700;
            text-align: center;
        }
        
        .center{
            margin-top: 50px;
            .center_top{
                width: 900px;
                margin: 0 auto;
                display: flex;
                justify-content: space-between;
                
                button {
                    margin-right: 20px;
                    padding: 2px 10px;
                }
            }
            .table{
                width: 900px;
                margin: 0 auto;
                margin-top: 15px;
                
                tr{
                    border: 1px solid #000;
                }
        
                table {
                    border-collapse: collapse;
                }
                
                th{
                    height: 18px;
                    line-height: 18px;
                    background-color: #ccc;
                }
                td,
                th {
                    padding: 10px;
                }
                td{
                    button{
                        margin-right: 10px;
                    }
                }
            }
        }
        
        .end{
        
            width: 900px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            
            button{
                margin-top: 5px;
            }
        }
    }
    
</style>
